
#include <string>

static int num = 1;

typedef void (*callback_t)();
class Thread
{
public:
  Thread(callback_t cb) : _tid(0), _startTimestamp(0), _threadname(""), _isRuning(false), _cb(cb)
  {
  }

  static void *threadRoutine(void *args)
  {
    Thread *td = static_cast<Thread *>(args);
    td->Entery();
    return nullptr;
  }

  void Run()
  {
    _threadname = "thread-" + std::to_string(num++);
    _startTimestamp = time(nullptr);
    _isRuning = true;

    pthread_create(&_tid, nullptr, threadRoutine, this);
  }

  void Join()
  {
    pthread_join(_tid, nullptr);
    _isRuning = false;
  }

  std::string getThreadName()
  {
    return _threadname;
  }

  int getStartTimestamp()
  {
    return _startTimestamp;
  }

  bool getIsRuning()
  {
    return _isRuning;
  }

  void Entery()
  {
    _cb();
  }

  ~Thread()
  {
  }

private:
  pthread_t _tid;
  int _startTimestamp;
  std::string _threadname;
  bool _isRuning;

  callback_t _cb;
};